package besteAukera;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Vector;

public class BusHamartarBitar extends AteLogikoak {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Color kolorea;
	private Vector<Hanka> hankaBektorea ;
	private Vector<Hanka> sarreraBektorea;
	private Hanka s1, i1,i2,i3,i4,i5,i6,i7,i8;
	private boolean aldatua;
	Vector<Integer> bitarBektorea;
	private String logika;
	public BusHamartarBitar(int x1, int y1, int hankaKop, int sarreraKop,
			String motaFis, Color kolo,String log) {
		super(x1, y1, hankaKop, sarreraKop, motaFis, kolo);
	logika=log;
		aldatua=false;
		kolorea=kolo;
		if (getSarreraKopMax()== 2) {
	
			s1 = new Hanka(x, y+5, logika, "s", 0, this, "h", "ez", false);
			i1 = new Hanka(x+40, y , logika, "i", 1, this, "h", "ez", true);
			i2 = new Hanka(x+40, y + 10, logika, "i", 2, this, "h", "ez",true);
			
			lotList[0] = s1;
			lotList[1] = i1;
			lotList[2] = i2;
				
		} else if (getSarreraKopMax() == 3) {
			
				s1 = new Hanka(x, y+10, logika, "s", 0, this, "h", "ez", false);
				i1 = new Hanka(x+40, y, logika, "i", 1, this, "h", "ez", true);
				i2 = new Hanka(x+40, y + 10, logika, "i", 2, this, "h", "ez", true);
				i3 = new Hanka(x+40, y + 20, logika, "i", 3, this, "h", "ez",
						true);
				lotList[0] = s1;
				lotList[1] = i1;
				lotList[2] = i2;
				lotList[3] = i3;
			

		} else if (getSarreraKopMax() == 4) {
				
				s1 = new Hanka(x, y+15, logika, "s", 0, this, "h", "ez", false);
				i1 = new Hanka(x+40, y , logika, "i", 1, this, "h", "ez", true);
				i2 = new Hanka(x+40, y + 10, logika, "i", 2, this, "h", "ez", true);
				i3 = new Hanka(x+40, y + 20, logika, "i", 3, this, "h", "ez", true);
				i4 = new Hanka(x+40, y + 30, logika, "i", 4, this, "h", "ez",true);
				lotList[0] = s1;
				lotList[1] = i1;
				lotList[2] = i2;
				lotList[3] = i3;
				lotList[4] = i4;

		} else if (getSarreraKopMax() == 5) {
			
				s1 = new Hanka(x, y+20, logika, "s", 0, this, "h", "ez", false);
				i1 = new Hanka(x+40, y , logika, "i", 1, this, "h", "ez", true);
				i2 = new Hanka(x+40, y + 10, logika, "i", 2, this, "h", "ez", true);
				i3 = new Hanka(x+40, y + 20, logika, "i", 3, this, "h", "ez", true);
				i4 = new Hanka(x+40, y + 30, logika, "i", 4, this, "h", "ez",true);
				i5 = new Hanka(x+40, y + 40, logika, "i", 5, this, "h", "ez",true);
				lotList[0] = s1;
				lotList[1] = i1;
				lotList[2] = i2;
				lotList[3] = i3;
				lotList[4] = i4;
				lotList[5] = i5;
			

		} else if (getSarreraKopMax() == 6) {
			
				s1 = new Hanka(x, y+25, logika, "s", 0, this, "h", "ez", false);
				i1 = new Hanka(x+40, y , logika, "i", 1, this, "h", "ez", true);
				i2 = new Hanka(x+40, y + 10, logika, "i", 2, this, "h", "ez", true);
				i3 = new Hanka(x+40, y + 20, logika, "i", 3, this, "h", "ez", true);
				i4 = new Hanka(x+40, y + 30, logika, "i", 4, this, "h", "ez",true);
				i5 = new Hanka(x+40, y + 40, logika, "i", 5, this, "h", "ez",true);
				i6 = new Hanka(x+40, y + 50, logika, "i", 6, this, "h", "ez",true);
				lotList[0] = s1;
				lotList[1] = i1;
				lotList[2] = i2;
				lotList[3] = i3;
				lotList[4] = i4;
				lotList[5] = i5;
				lotList[6] = i6;
			

		} else if (getSarreraKopMax() == 7) {
			
				s1 = new Hanka(x, y+30, logika, "s", 0, this, "h", "ez", false);
				i1 = new Hanka(x+40, y , logika, "i", 1, this, "h", "ez", true);
				i2 = new Hanka(x+40, y + 10, logika, "i", 2, this, "h", "ez", true);
				i3 = new Hanka(x+40, y + 20, logika, "i", 3, this, "h", "ez", true);
				i4 = new Hanka(x+40, y + 30, logika, "i", 4, this, "h", "ez",true);
				i5 = new Hanka(x+40, y + 40, logika, "i", 5, this, "h", "ez",true);
				i6 = new Hanka(x+40, y + 50, logika, "i", 6, this, "h", "ez",true);
				i7 = new Hanka(x+40, y + 60, logika, "i", 7, this, "h", "ez",true);
				lotList[0] = s1;
				lotList[1] = i1;
				lotList[2] = i2;
				lotList[3] = i3;
				lotList[4] = i4;
				lotList[5] = i5;
				lotList[6] = i6;
				lotList[7] = i7;
			

		} else if (getSarreraKopMax()== 8) {
			
			
				s1 = new Hanka(x, y+35, logika, "s", 0, this, "h", "ez", false);
				i1 = new Hanka(x+40, y , logika, "i", 1, this, "h", "ez", true);
				i2 = new Hanka(x+40, y + 10, logika, "i", 2, this, "h", "ez", true);
				i3 = new Hanka(x+40, y + 20, logika, "i", 3, this, "h", "ez", true);
				i4 = new Hanka(x+40, y + 30, logika, "i", 4, this, "h", "ez",true);
				i5 = new Hanka(x+40, y + 40, logika, "i", 5, this, "h", "ez",true);
				i6 = new Hanka(x+40, y + 50, logika, "i", 6, this, "h", "ez",true);
				i7 = new Hanka(x+40, y + 60, logika, "i", 7, this, "h", "ez",true);
				i8 = new Hanka(x+40, y + 70, logika, "i", 8, this, "h", "ez",true);
				lotList[0] = s1;
				lotList[1] = i1;
				lotList[2] = i2;
				lotList[3] = i3;
				lotList[4] = i4;
				lotList[5] = i5;
				lotList[6] = i6;
				lotList[7] = i7;
				lotList[8] = i8;
			

		}
		
		// TODO Auto-generated constructor stub
	}

	public void marraztu(Graphics g) {
		if (getAukeratua() == true) {
			kolorea = Color.GRAY;
		} else {
			kolorea = Color.black;
		}
		g.setColor(kolorea);
		if (getSarreraKopMax() == 2) {
			g.drawLine(x + 20, y, x + 20, y + 10);
			
				s1.marraztu(g);
				i1.marraztu(g);
				i2.marraztu(g);
			
		} else if (getSarreraKopMax() == 3) {
			g.drawLine(x + 20, y, x + 20, y + 20);
		
				s1.marraztu(g);
				i1.marraztu(g);
				i2.marraztu(g);
				i3.marraztu(g);
			
		} else if (getSarreraKopMax() == 4) {
			g.drawLine(x + 20, y, x + 20, y + 30);
				s1.marraztu(g);
				i1.marraztu(g);
				i2.marraztu(g);
				i3.marraztu(g);
				i4.marraztu(g);
				
			
		} else if (getSarreraKopMax() == 5) {
			g.drawLine(x + 20, y, x + 20, y + 40);
			
				s1.marraztu(g);
				i1.marraztu(g);
				i2.marraztu(g);
				i3.marraztu(g);
				i4.marraztu(g);
				i5.marraztu(g);
				
			
		} else if (getSarreraKopMax() == 6) {
			g.drawLine(x + 20, y, x + 20, y + 50);
			
				s1.marraztu(g);
				i1.marraztu(g);
				i2.marraztu(g);
				i3.marraztu(g);
				i4.marraztu(g);
				i5.marraztu(g);
				i6.marraztu(g);
			

		} else if (getSarreraKopMax() == 7) {
			g.drawLine(x + 20, y, x + 20, y + 60);
			
				s1.marraztu(g);
				i1.marraztu(g);
				i2.marraztu(g);
				i3.marraztu(g);
				i4.marraztu(g);
				i5.marraztu(g);
				i6.marraztu(g);
				i7.marraztu(g);
				
			
		} else if (getSarreraKopMax() == 8) {
			g.drawLine(x + 20, y, x + 20, y + 70);
			
				s1.marraztu(g);
				i1.marraztu(g);
				i2.marraztu(g);
				i3.marraztu(g);
				i4.marraztu(g);
				i5.marraztu(g);
				i6.marraztu(g);
				i7.marraztu(g);
				i8.marraztu(g);
			
			
		}
	}
	public boolean isAldatua(){
		return aldatua;
	}
	public void setAldatua(boolean ald){
	
		aldatua=ald;
	}
	@Override
	protected void funtzioLogikoa(Integer... values) {
		// TODO Auto-generated method stub
		
		Balioa bal=new Balioa(s1.getBitKopurua());
		Vector<Integer> bitarra=bal.getBalioBitarra(s1.getSarrera().getBalioa());
			if(getSarreraKopMax()==2)
			{			 
				lotList[1].getIrteera().setBalioa((int)bitarra.get(0));
				lotList[2].getIrteera().setBalioa((int)bitarra.get(1));
			}
			else if(getSarreraKopMax()==3){
				lotList[1].getIrteera().setBalioa(bitarra.elementAt(0));
				lotList[2].getIrteera().setBalioa(bitarra.elementAt(1));
				lotList[3].getIrteera().setBalioa(bitarra.elementAt(2));
			}
			else if(getSarreraKopMax()==4){
				lotList[1].getIrteera().setBalioa(bitarra.get(0));
				lotList[2].getIrteera().setBalioa(bitarra.get(1));
				lotList[3].getIrteera().setBalioa(bitarra.get(2));
				lotList[4].getIrteera().setBalioa(bitarra.get(3));
				
			}
			else if(getSarreraKopMax()==5){
				lotList[1].getIrteera().setBalioa(bitarra.get(0));
				lotList[2].getIrteera().setBalioa(bitarra.get(1));
				lotList[3].getIrteera().setBalioa(bitarra.get(2));
				lotList[4].getIrteera().setBalioa(bitarra.get(3));
				lotList[5].getIrteera().setBalioa(bitarra.get(4));
				
			}
			else if(getSarreraKopMax()==6){
				lotList[1].getIrteera().setBalioa(bitarra.get(0));
				lotList[2].getIrteera().setBalioa(bitarra.get(1));
				lotList[3].getIrteera().setBalioa(bitarra.get(2));
				lotList[4].getIrteera().setBalioa(bitarra.get(3));
				lotList[5].getIrteera().setBalioa(bitarra.get(4));
				lotList[6].getIrteera().setBalioa(bitarra.get(5));
				
			}
			else if(getSarreraKopMax()==7){
				lotList[1].getIrteera().setBalioa(bitarra.get(0));
				lotList[2].getIrteera().setBalioa(bitarra.get(1));
				lotList[3].getIrteera().setBalioa(bitarra.get(2));
				lotList[4].getIrteera().setBalioa(bitarra.get(3));
				lotList[5].getIrteera().setBalioa(bitarra.get(4));
				lotList[6].getIrteera().setBalioa(bitarra.get(5));
				lotList[7].getIrteera().setBalioa(bitarra.get(6));
				
			}
			else if(getSarreraKopMax()==8){
				lotList[1].getIrteera().setBalioa(bitarra.get(0));
				lotList[2].getIrteera().setBalioa(bitarra.get(1));
				lotList[3].getIrteera().setBalioa(bitarra.get(2));
				lotList[4].getIrteera().setBalioa(bitarra.get(3));
				lotList[5].getIrteera().setBalioa(bitarra.get(4));
				lotList[6].getIrteera().setBalioa(bitarra.get(5));
				lotList[7].getIrteera().setBalioa(bitarra.get(6));
				lotList[8].getIrteera().setBalioa(bitarra.get(7));
			}
		}
	
	
	

	@Override
	public Vector<Hanka> getHankak() {
		// TODO Auto-generated method stub
		hankaBektorea = new Vector<Hanka>();
		if (getSarreraKopMax() == 2) {
			
				hankaBektorea.add(s1);
				hankaBektorea.add(i1);
				hankaBektorea.add(i2);
			
			
		} else if (getSarreraKopMax() == 3) {
			
				hankaBektorea.add(s1);
				hankaBektorea.add(i1);
				hankaBektorea.add(i2);
				hankaBektorea.add(i3);
			
			
		} else if (getSarreraKopMax() == 4) {
			
				hankaBektorea.add(s1);
				hankaBektorea.add(i1);
				hankaBektorea.add(i2);
				hankaBektorea.add(i3);
				hankaBektorea.add(i4);
			
			

		} else if (getSarreraKopMax() == 5) {
			
				hankaBektorea.add(s1);
				hankaBektorea.add(i1);
				hankaBektorea.add(i2);
				hankaBektorea.add(i3);
				hankaBektorea.add(i4);
				hankaBektorea.add(i5);
				
			
		} else if (getSarreraKopMax() == 6) {
			
				hankaBektorea.add(s1);
				hankaBektorea.add(i1);
				hankaBektorea.add(i2);
				hankaBektorea.add(i3);
				hankaBektorea.add(i4);
				hankaBektorea.add(i5);
				hankaBektorea.add(i6);
				
			

		} else if (getSarreraKopMax() == 7) {
		
				hankaBektorea.add(s1);
				hankaBektorea.add(i1);
				hankaBektorea.add(i2);
				hankaBektorea.add(i3);
				hankaBektorea.add(i4);
				hankaBektorea.add(i5);
				hankaBektorea.add(i6);
				hankaBektorea.add(i7);
				
			

		} else if (getSarreraKopMax() == 8) {
			
				hankaBektorea.add(s1);
				hankaBektorea.add(i1);
				hankaBektorea.add(i2);
				hankaBektorea.add(i3);
				hankaBektorea.add(i4);
				hankaBektorea.add(i5);
				hankaBektorea.add(i6);
				hankaBektorea.add(i7);
				hankaBektorea.add(i8);
				
		}
		return hankaBektorea;
	}

	@Override
	public Vector<Hanka> getSarreraHankak() {
		// TODO Auto-generated method stub
		sarreraBektorea = new Vector<Hanka>();
		sarreraBektorea.add(s1);
		return sarreraBektorea;
	}

	public boolean barruanDago(int x, int y) {
		if (getSarreraKopMax() == 2) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 15 > y))
				return true;
			else
				return false;

		} else if (getSarreraKopMax() == 3) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 25 > y))
				return true;
			else
				return false;

		} else if (getSarreraKopMax() == 4) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 35 > y))
				return true;
			else
				return false;

		} else if (getSarreraKopMax() == 5) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 45 > y))
				return true;
			else
				return false;

		} else if (getSarreraKopMax() == 6) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 55 > y))
				return true;
			else
				return false;

		} else if (getSarreraKopMax() == 7) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 65 > y))
				return true;
			else
				return false;

		} else if (getSarreraKopMax() == 8) {
			if ((this.x + 15 < x) && (this.x + 25 > x) && (this.y < y)
					&& (this.y + 75 > y))
				return true;
			else
				return false;

		}
		return false;
	}
	public void setHankaKopurua(int hankaKop){
		hankaKopMax=hankaKop;
	}
	public String getLogika(){
		return logika;
	}
}
